/*
 * Copyright (c) 2022-present Charles7c Authors. All Rights Reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package cn.matezk.dms.things.mapper;

import cn.matezk.dms.things.model.entity.DeviceDO;
import cn.matezk.dms.things.model.query.DeviceQuery;
import cn.matezk.dms.things.model.resp.*;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import top.continew.starter.data.mp.base.BaseMapper;

import java.util.List;

/**
 * 设备 Mapper
 *
 * @author 程道林
 * @since 2024/12/01 22:10
 */
public interface DeviceMapper extends BaseMapper<DeviceDO> {
    @Update("update t_device set status = #{status} where device_id = #{deviceId}")
    int updateStatusByDeviceId(@Param("deviceId") String deviceId, @Param("status") String status);

    int updateByPrimaryKeySelective(DeviceDO device);

    @Select("select id, device_id, alias_name, dept_id, iccid, device_status, csq, desired, reported from t_device where id = #{id}")
    DeviceDetailResp detail(Long id);

    DeviceResp selectByPrimaryKey(Long id);

    DeviceDO select(@Param("productId") String productId, @Param("deviceName") String deviceName);

    @Select("select id, device_id, alias_name, dept_id, iccid, device_status, csq from t_device where device_id = #{deviceId}")
    DeviceDO selectByDeviceId(@Param("deviceId") String deviceId);

    @Select("select device_name from t_device where product_id = #{productId} and find_in_set(version, #{version})")
    List<String> selectByProductVersion(@Param("productId") String productId, @Param("version") String version);

    /**
     * 分页查询列表
     *
     * @param page        分页条件
     * @param deviceQuery 查询条件
     * @return 分页列表信息
     */
    IPage<DeviceResp> selectPage(@Param("page") IPage<DeviceDO> page, @Param("query") DeviceQuery deviceQuery);

    List<PropertyResp> selectPropertyBatch(List<String> deviceIds);

    int unbind(String deviceId);

    SaleStatResp saleStat();

    HotSalesResp hotSales();

    MonthSaleResp monthSale();

    List<String> selectUnknowIccid();
}